<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BookIsbn extends Model
{
    use \jdavidbakr\ReplaceableModel\ReplaceableModel;

    public function getImageAttribute($value)
    {
        $imgUrl = urlencode($value);
        $url    = route('douban.img') . '?url=' . $imgUrl;
        return $url;
    }

    public function bookisbn()
    {
        return $this->hasOne(Cart::class, 'isbn', 'isbn13');
    }

    public function getImageUrl()
    {
        $urlarr = parse_url($this->image);
        parse_str($urlarr['query'], $parr);
        return urldecode($parr['url']);
    }
}
